package com.jk.controller.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jk.controller.BaseController;
import com.jk.pojo.Project;
import com.jk.service.ProjectService;

/**
 * 项目管理
 * @author cuiP
 *
 */
@Controller
@RequestMapping("/admin/project/")
public class ProjectController extends BaseController {

	private static final String JSP_PATH = "/project/";
	
	@Resource
    private	ProjectService projectService;
	
	/**
	 * 项目管理列表
	 * @param request
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("list.do")
	public String list(HttpServletRequest request,ModelMap modelMap) throws Exception{
//		String projectName = request.getParameter("projectName");
//		String firstTimeStr = request.getParameter("firstTime");
//		String endTimeStr = request.getParameter("endTime");
		//查询
//		List<Project> list = projectService.queryList(projectName, firstTimeStr, endTimeStr);
		List<Project> list = projectService.findProjectList();
		//回显
		modelMap.put("list", list);
//		modelMap.put("projectName", projectName);
//		modelMap.put("firstTime", firstTimeStr);
//		modelMap.put("endTime", endTimeStr);
		return JSP_PATH+"list";
	}
	
	/**
	 * 删除
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="delete/{id}.do",method=RequestMethod.DELETE)
	public Map<String, Object> delete(HttpServletRequest request,@PathVariable("id") Long id){
		Map<String, Object> messageMap = new HashMap<String,Object>();
		try {
			projectService.deleteById(id);
			//TODO
			messageMap.put("status", SUCCESS);
			messageMap.put("message",SUCCESS_DELETE_MESSAGE);
		} catch (Exception e) {
			//e.printStackTrace();
			messageMap.put("status", FAILURE);
			messageMap.put("message","删除失败!");
		}
		return messageMap;
	}
	
}
